package keeto.com.vn.bms.network.task;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.model.HospitalRecordInputDataModel;
import keeto.com.vn.bms.network.IBMSProtocol;
import keeto.com.vn.bms.network.request.SendUpdateHospitalRecordRequest;
import keeto.com.vn.bms.network.response.SendUpdateHospitalRecordResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskSendUpdateHospitalRecord extends AbstractTask {

	private String authenKey;
	private String Com_hos_id;
	private String Revenue;
	private ArrayList<HospitalRecordInputDataModel> dataRecord;
	private String date;

	public TaskSendUpdateHospitalRecord(BMSListener listener, IBMSCore core,
			String authenKey,String Com_hos_id, String Revenue,
			ArrayList<HospitalRecordInputDataModel> dataRecord, String Date) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.authenKey=authenKey;
		this.Com_hos_id=Com_hos_id;
		this.Revenue=Revenue;
		this.dataRecord=dataRecord;
		this.date=Date;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		SendUpdateHospitalRecordRequest request = new SendUpdateHospitalRecordRequest();
		request.setAuthenKey(authenKey);
		request.setCom_hos_id(Com_hos_id);
		request.setRevenue(Revenue);
		request.setDataRecord(dataRecord);
		request.setDate(date);
		SendUpdateHospitalRecordResponse response = protocol
				.sendUpdateHosRecord(request);
		for (BMSListener mListener : listener) {
			mListener.finishSendUpdateHosRecord(response.getReturnCode(),
					response.getResultMsg());
		}

	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mListener : listener) {
			mListener.finishSendUpdateHosRecord(
					IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, "");
		}
	}

}
